package cn.edu.sdyu.ie.crs.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

//@Schema(name = "用户信息")
@ApiModel("用户信息")
@Setter
@Getter
@Entity
public class User  implements UserDetails{

    //@Schema(name = "用户Id")
    @ApiModelProperty("用户Id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @ApiModelProperty("用户名")
    private String username;  // 用户名
    @ApiModelProperty("姓名")
    private String name;  // 姓名
    @ApiModelProperty("手机")
    private String phone;  // 手机
    @ApiModelProperty("用户类型")
    private Integer userType;  // 用户类型
    @JsonIgnore
    @ApiModelProperty("密码")
    private String password;  // 密码
    @ApiModelProperty("校园卡号")
    private String cardNumber;  // 校园卡号
    @ApiModelProperty("邮箱")
    private String email;  // 邮箱
    @ApiModelProperty("用户状态")
    private Integer userStatus;  // 用户状态
    @ApiModelProperty("创建时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;  // 创建时间

    @ManyToOne
    @JoinColumn(foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Role role;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return new ArrayList<>();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}